#include "SGException.h"

SGException::SGException(const std::string& strContent) throw() //构造函数
  : m_strContent{ strContent }
{
}

const char* SGException::what() const throw() //虚函数
{
  return m_strContent.c_str();
}

/// Print error message, prefer this to the above generic error
/// message
void sg_exception(
  const std::string& location, const std::string& task, const std::string& reason)
{
  std::stringstream s;
  s << "\n\n***\n"
    << "***  "
       "---------------------------------------------------------------------"
       "----\n"
    << "***  错误：    " << task << "时出错。\n"
    << "***  原因：  " << reason << "。\n"
    << "***  位置：   该错误发生在-- " << location << "。\n"
    << "***  "
       "---------------------------------------------------------------------"
       "----\n"
    << "***\n";

  throw SGException(s.str());
}

void _sg_exception(const std::string& file, const unsigned long& line,
  const std::string& function, const std::string& reason)
{
  std::stringstream location;
  location << file << " (行号 " << line << ")";
  std::stringstream task;
  task << "执行函数 " << function << "() ";
  sg_exception(location.str(), task.str(), reason);
}
